﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RSALicUI
{

    /// <summary>
    /// 生成二维码的控件
    /// </summary>
    public partial class QRMakerCtrl : UserControl, IQRMaker
    {
        public QRMakerCtrl()
        {
            InitializeComponent();
        }

        public Image GetQrImage()
        {
            return this.BackgroundImage;
        }

        public void SetData(string data)
        {
            var bmp = RSALicCore.QRCodeHelper.Create(data);
            this.BackgroundImage = bmp;
            this.Invalidate();
        }

        private void MenuSaveQrCode_Click(object sender, EventArgs e)
        {
            using (var dlg = new SaveFileDialog())
            {
                dlg.Filter = "图片文件|*.png";
                dlg.Title = "保存二维码";
                var res = dlg.ShowDialog();
                if (res == DialogResult.OK)
                {
                    this.GetQrImage().Save(dlg.FileName);
                }
            }
        }
    }
}
